/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Tests;

import universityModel.organization.*;
import universityModel.person.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
import universityModel.curriculum.Curriculum;
import universityModel.curriculum.Day;
import universityModel.curriculum.WeekDays;
import universityModel.lesson.*;
import universityModel.utils.ArrayModel;

/**
 *
 * @author Дмитрий
 */
public class GroupTest {
    private ExtendedGroupView kv81;

    private Student iAm;
    private StudentInterface fr;
    private StudentInterface face;

    private LessonInterface Math;
    private LectureInterface Fyth;

    @BeforeClass
    public static void setUpClass() throws Exception {
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }
    
    @Before
    public void setUp() {
        kv81 = new Group("KV-81", 4);
        iAm = new Student(new Name("Dmytro", "Parkhomenko"),
                          new BiographicalData("24.09.1991", "Ukraine, Krolevetz city", 12345), 
                          new StudentInfo("Computer networks", "KV-81", 107), 
                          new StudyPlace("KPI", "FMP"));  
       
        Math = new ExamInterface() {

            public void setExamTickets(ArrayModel<String> examTickets) {
                throw new UnsupportedOperationException("Not supported yet. 1");
            }

            public void setGroup(String name) {
                throw new UnsupportedOperationException("Not supported yet. 2");
            }

            public void add(String group) {
                throw new UnsupportedOperationException("Not supported yet. 3");
            }

            public ArrayModel<String> getGroups() {
                throw new UnsupportedOperationException("Not supported yet. 4");
            }

            public void setTeacher(Name teacher) {
                throw new UnsupportedOperationException("Not supported yet. 5");
            }

            public void setTime(Time time) {
                throw new UnsupportedOperationException("Not supported yet. 6");
            }

            public void setVenue(Venue venue) {
                throw new UnsupportedOperationException("Not supported yet. 7");
            }

            public Time getNumPair() {
                throw new UnsupportedOperationException("Not supported yet. 8");
            }

            public int getWeekDay() {
                return 0;
               // throw new UnsupportedOperationException("Not supported yet. 9");
            }

            @Override
            public String toString() {
                return "exam";
            }
        };
      
        Fyth = new LectureInterface() {

            public void setHomeTask(String homeTask) {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public String getHomeTask() {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public void setGroup(String name) {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public void add(String group) {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public ArrayModel<String> getGroups() {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public void setTeacher(Name teacher) {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public void setTime(Time time) {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public void setVenue(Venue venue) {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public Time getNumPair() {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public int getWeekDay() {
                return 0;
                //throw new UnsupportedOperationException("Not supported yet.");
            }
            
            @Override
            public String toString() {
                return "lecture";
            }
        };

        fr = new StudentInterface() {

            public String getNameGroup() {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public String getProffesionalDescription() {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public double getStudentRanking() {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public void setStudentRanking(int newStudentRanking) {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public void participateLearningProcess() {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public int getKnowledges() {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public Name getName() {
               return new Name("Vasy", "Pupkin");
            }

            public void setLearningProcess(LearningProcess learningProcess) {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public void performLearningProcess() {
                throw new UnsupportedOperationException("Not supported yet.");
            }
        };

        face = new StudentInterface() {

            public String getNameGroup() {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public String getProffesionalDescription() {
                return "student";
            }

            public double getStudentRanking() {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public void setStudentRanking(int newStudentRanking) {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public void participateLearningProcess() {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public int getKnowledges() {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public Name getName() {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public void setLearningProcess(LearningProcess learningProcess) {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            public void performLearningProcess() {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            @Override
            public String toString() {
                return "Man";
            }
        };
    }
    
    @After
    public void tearDown() {
    }
   
    @Test
    public void shouldGetCorrectStudentWhenAddStudent() {
        //given
      
        //when
        kv81.addStudent(iAm);
        //then
        assertEquals(kv81.getStudent(0), iAm);
    }
    
    @Test
    public void shouldBeEmptyWhenAddDelStudent() {
        //given
        
        //when
        kv81.addStudent(iAm);
        kv81.delStudent(iAm);
        //then
        assertTrue(kv81.isEmpty());
    }
    
    @Test
    public void shouldCurriculumForOneDayWhenAddOneLesson() {
        //given
        Day day = new Day(WeekDays.MONDAY);
        String curriculumForOneDay =  "Day: MONDAY\n"
                              + "lecture\n";
        //when
        day.add(Fyth);
        //then
        assertEquals(day.getDay(), curriculumForOneDay);
    }
   
    @Test
    public void shouldEqualsTrueWhenAddLesson() {
        //given
        Curriculum curriculum = new Curriculum("KV-81");
        String expectedCurriculum = "Day: MONDAY\n"
                                        + "exam\n"
                                        + "lecture\n"
                                    + "Day: TUESDAY\n"
                                    + "Day: WEDNESDAY\n"
                                    + "Day: THURSDAY\n"
                                    + "Day: FRIDAY\n";        
        //when
        curriculum.addLesson(Math);
        curriculum.addLesson(Fyth);
        //then
        assertEquals(curriculum.toString(), expectedCurriculum);
    }
    
    @Test
    public void shouldGetEmptyCurriculumWhenNoAddLessons() {
        //given
        String expectedCurriculum =   "Day: MONDAY\n"
                                    + "Day: TUESDAY\n"
                                    + "Day: WEDNESDAY\n"
                                    + "Day: THURSDAY\n"
                                    + "Day: FRIDAY\n";
        //when
        
        //then
        assertEquals(kv81.getCurriculum().toString(), expectedCurriculum);
    }
    
    @Test
    public void shouldBeOneWhenAddOneStuden() {
        //given
        
        //when
        kv81.addStudent(iAm);
        //then
        assertEquals(kv81.getSize(), 1);
    }
    
    @Test
    public void shouldEqualsFalseWhenDifferentGroups() {
        //given
        ExtendedGroupView kv82 = new Group("KV-82", 4);
        //when
        //then
        assertFalse(kv81.equals(kv82));
    }

    @Test
    public void shouldSetCorectCurriculumAfterAddLectureToExternalCurriculum() {
        //given
        String expectedCurriculum = "Day: MONDAY\n"
                                       + "Math\n"
                                       + "Yriy Bohonov\n"
                                       + "Number of corps: 18\n"
                                       + "Number of auditory: 308\n"
                                       + "Number of pair: 1\n"
                                       + "Data: 24.09.1991\n"
                                       + "homeTask: Nothing\n"
                                    + "Day: TUESDAY\n"
                                    + "Day: WEDNESDAY\n"
                                    + "Day: THURSDAY\n"
                                    + "Day: FRIDAY\n";

        Curriculum curriculum = new Curriculum("KV-81");
        
        LectureInterface newMath = new Lecture(new Name("Yriy", "Bohonov"),
                             new Time("24.09.1991", 1),
                             new Venue(18, 308), "Math", WeekDays.MONDAY);
        //when
        curriculum.addLesson(newMath);
        kv81.setCurriculum(curriculum);
        //then
        assertEquals(kv81.getCurriculum().toString(), expectedCurriculum);
    }

    @Test
    public void shouldGetCorectCurriculumAfterAddLectureFromGroup() {
        //given
        String expectedCurriculum = "Day: MONDAY\n"
                                       + "Math\n"
                                       + "Yriy Bohonov\n"
                                       + "Number of corps: 18\n"
                                       + "Number of auditory: 308\n"
                                       + "Number of pair: 1\n"
                                       + "Data: 24.09.1991\n"
                                       + "homeTask: Nothing\n"
                                    + "Day: TUESDAY\n"
                                    + "Day: WEDNESDAY\n"
                                    + "Day: THURSDAY\n"
                                    + "Day: FRIDAY\n";

         LectureInterface newMath = new Lecture(new Name("Yriy", "Bohonov"),
                             new Time("24.09.1991", 1),
                             new Venue(18, 308), "Math", WeekDays.MONDAY);
        //when
        kv81.addLesson(newMath);
        //then
        assertEquals(kv81.getCurriculum().toString(), expectedCurriculum);
    }

    @Test
    public void shouldGetExceptionWhenDelAnknownStudent() {
        //given
        try {
            //when
            kv81.delStudent(fr);
            fail("Test is lier!!!");
        } catch(IndexOutOfBoundsException ex) {
            //then
            assertTrue(true);
        }
    }

     @Test
     public void shouldGetCorrectListWhenAddStudent() {
        //give
         String expectedList = "Man\n"
                               + "student";
        //when
        kv81.addStudent(face);
        //then
         assertEquals(kv81.getStudentsList(), expectedList);
     }
}
